<template>
  <div class="my_div">
    <img :src="dogImgUrl" alt="" />
    <p
      @click="changeColor()"
      :style="{ color: Color, backgroundColor: bgColor }"
    >
      {{ dogName }}
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      Color: "",
      bgColor: "",
    };
  },
  props: {
    dogImgUrl: {
      type: String,
      required: true,
      default: "https://scpic.chinaz.net/files/pic/pic9/202003/zzpic23514.jpg",
    },
    dogName: {
      type: String,
      required: true,
      default: "这是一个孤独可怜的狗",
    },
  },
  methods: {
    changeColor() {
      this.Color = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(
        Math.random() * 256
      )},${Math.floor(Math.random() * 256)})`;
      this.bgColor = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(
        Math.random() * 256
      )},${Math.floor(Math.random() * 256)})`;
      this.$emit("sonDogName", this.dogName);
    },
  },
};
</script>

<style scoped>
.my_div {
  width: 200px;
  border: 1px solid black;
  text-align: center;
  float: left;
}

.my_div img {
  width: 100%;
  height: 200px;
}
</style>
